using System;
using System.Text;
namespace CExceptionHandling
{
	/// <summary>
	/// Summary description for CCustomException.
	/// </summary>
	public class CCustomException
	{
		private string _strResponseString = string.Empty;

		public string XMLResponseCode
		{
			get
			{
				return _strResponseString;
			}
		}
		public CCustomException()
		{
			CreateSuccessReponse();
		}

		public CCustomException(Exception ex)
		{
			CreateErrorReponse( ex);
		}

		private void CreateErrorReponse( Exception ex)
		{
			StringBuilder sbMsg  = new StringBuilder ();
			sbMsg.Append("<DATA>");
			sbMsg.Append("<RESPONSE>");
            sbMsg.Append("<RESULT>" + System.Configuration.ConfigurationSettings.AppSettings["ErrorResponse"].ToString() + "</RESULT>");
			sbMsg.Append("<MESSAGE>");
			sbMsg.Append(ShowCustomeErrors(ex) );
			sbMsg.Append("</MESSAGE>");
			sbMsg.Append("</RESPONSE>");
			sbMsg.Append("</DATA>");
			_strResponseString = sbMsg.ToString();
		}

		/// <summary>
		/// ADD CUSTOMER USER FRIENDLY MESSAGE AS PER EXCEPTIONS
		/// </summary>
		/// <param name="ex"></param>
		/// <returns></returns>
		private string ShowCustomeErrors(Exception ex)
		{
			return ex.Message;
		}

		private void CreateSuccessReponse()
		{
			StringBuilder sbMsg  = new StringBuilder ();
			sbMsg.Append("<RESPONSE>");
            sbMsg.Append("<RESULT>" + System.Configuration.ConfigurationSettings.AppSettings["SuccessResponse"].ToString() + "</RESULT>");
			sbMsg.Append("<MESSAGE></MESSAGE>");
			sbMsg.Append("</RESPONSE>");
			_strResponseString = sbMsg.ToString();
		}
	}
}
